import Vue from 'vue'
import App from './App.vue'
import router from './router/index'

Vue.config.productionTip = false

import  './assets/css/global.css'
import qs from 'qs';
Vue.prototype.$qs = qs

// 引入echarts
// import echarts from "echarts"
import * as echarts from "echarts"

Vue.prototype.$echarts = echarts


//引入地址
import MyUrl from './plugins/url'
Vue.prototype.$MyUrl = MyUrl;
import axios from 'axios'
//设置默认 路径
axios.defaults.baseURL=MyUrl.serverUrl
//设置拦截器  ????




//设置axios的请求拦截
axios.interceptors.request.use(config=>{
  console.log("============请求拦截=============")
  //在请求头中 设置 token 向后台发送
  let token = sessionStorage.getItem("token");
  if (token){
    //设置请求头
    config.headers["token"] = token ;
  }
  return config ;
})

//回应拦截器
axios.interceptors.response.use(config=>{
  console.log("========================回应拦截=========================")
  let data = config.data ;
  if (data == '0'){

    router.push('/login');
  }else if (data == '1'){

    router.push('/login');
  }else if (data == '2'){

    router.push('/login');
  }else if (data == '3'){

    router.push('/login');
  }
  return config ;
})


Vue.prototype.$axios = axios;

import ElementUI from 'element-ui'
Vue.use(ElementUI)
import 'element-ui/lib/theme-chalk/index.css';



new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
